<!-- <template>
  <el-menu class="el-menu-vertical-demo"
           @open="handleOpen"
           @close="handleClose"
           :collapse="isCollapse()"
           background-color="#545c64"
           text-color="#fff"
           active-text-color="#ffd04b">
    <h3 style="color: white; margin: 15px; " v-show="!isCollapse()">设备智能维护系统</h3>
    <h3 style="color: white; margin: 15px;" v-show="isCollapse()">系统</h3>
    
    <el-submenu :index="item.label" v-for="item in hasChildren" :key="item.path" @click="clickMenu(item)">
      <template slot="title">
        <i :class="'el-icon-'+item.icon"></i>
        <span slot="title">{{ item.label }}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item :index="subItem.path"
                      v-for="(subItem,subIndex) in item.children"
                      :key="subIndex"
                      @click="clickMenu(subItem)"
                      :path="subItem.path">
          <i :class="'el-icon-'+subItem.icon"></i>
          <span slot="title">{{ subItem.label }}</span>
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>

    <el-menu-item :index="item.path"
                  v-for="item in noChildren"
                  :key="item.path"
                  @click="clickMenu(item)"
                 :path="item.path">
      <i :class="'el-icon-'+item.icon"></i>
      <span slot="title">{{ item.label }}</span>
    </el-menu-item> -->
   
  <!-- </el-menu>

</template> -->

<template>
   <el-menu class="el-menu-vertical-demo"
       @open="handleOpen"
       @close="handleClose"
       :collapse="isCollapse()"
       background-color="#545c64"
       text-color="#fff"
       active-text-color="#ffd04b"
   >
    <h3 style="color: white; margin: 15px; " v-show="!isCollapse()">设备智能维护系统</h3>
    <h3 style="color: white; margin: 15px;" v-show="isCollapse()">系统</h3>
  
    <!-- 循环遍历菜单项 -->
    <template v-for="(item, index) in menu">
     <el-menu-item v-if="!item.children"
            :index="item.path"
            :key="index"
            @click="clickMenu(item)"
            :path="item.path"
     >
      <i :class="'el-icon-' + item.icon"></i>
      <span slot="title">{{ item.label }}</span>
     </el-menu-item>
  
     <el-submenu v-else :index="item.label"
           :key="item"
           @click="clickMenu(item)"
     >
      <template slot="title">
       <i :class="'el-icon-' + item.icon"></i>
       <span slot="title">{{ item.label }}</span>
      </template>
      <el-menu-item-group>
       <el-menu-item :index="subItem.path"
              v-for="(subItem, subIndex) in item.children"
              :key="subIndex"
              @click="clickMenu(subItem)"
       >
        <i :class="'el-icon-' + subItem.icon"></i>
        <span slot="title">{{ subItem.label }}</span>
       </el-menu-item>
      </el-menu-item-group>
     </el-submenu>
    </template>
   </el-menu>
  </template>
<script>

export default {
  name: "CompAside",
  data() {
    return {
      menu: [
        {
          path: "/home",
          name: "home",
          label: "首页",
          icon: "s-home",
          url: "Home/Home",
        },
        {
          path: '/baike',
          name: 'baike',
          label: "知识百科",
          icon: "notebook-2",
          url: "Baike/Baike"
        },
        {
          path: "/graph",
          name: "Graph",
          label: "故障图谱",
          icon: "picture-outline",
          children: [
            {
              path: "/graph/2dView",
              name: "2dView",
              label: "2D视图",
              icon: "goblet",
              url: "Graph/2dView"

            },
            {
              path: "/graph/3dView",
              name: "3dView",
              label: "3D视图",
              icon: "goblet-full",
              url: "Graph/3dView"
            }
          ]
        },
        {
          path: '/cause',
          name: "cause",
          label: "故障诊断",
          icon: "document-remove",
          url: "Cause/Cause"
        },
        {
          path: "/add",
          name: "Add",
          label: "设备知识库维护",
          icon: "document-remove",
          url: "Add/Add"
        },
        // {
        //   path: "/device",
        //   name: "device",
        //   label: "设备信息维护",
        //   icon: "s-tools",
        //   url: "DeviceManage/DeviceManage"
        // },
        // {
        //   path: "/tree",
        //   name: "Tree",
        //   label: "典型设备故障树生成",
        //   icon: "s-order",
        //   url: "Tree/Tree"
        // },
        // {
        //   path: "/user",
        //   name: "user",
        //   label: "用户管理",
        //   icon: "user-solid",
        //   url: "UserManage/UserManage",
        // },

        // {
        //   path: "/device_query",
        //   name: "device_query",
        //   label: "设备维护知识推荐",
        //   icon: "s-operation",
        //   url: "DQuery/DQuery"
        // },
        // {
        //   path: "/2dView",
        //   name: "2dView",
        //   label: "图谱展示",
        //   icon: "picture-outline",
        //   url: "Graph/Graph"
        // },
        // {
        //   path: "/case",
        //   name: "case",
        //   label: "故障案例库",
        //   icon: "s-order",
        //   url: "CaseManage/CaseManage"
        // },
        // {
        //   label: "其他",
        //   icon: "location",
        //   children: [
        //     {
        //       path: "/page1",
        //       name: "page1",
        //       label: "页面1",
        //       icon: "setting",
        //       url: "Other/PageOne"
        //     },
        //     {
        //       path: "/page2",
        //       name: "page2",
        //       label: "页面2",
        //       icon: "setting",
        //       url: "Other/PageTwo"
        //     }
        //   ]
        // }
      ]
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    clickMenu(item) {
      this.$router.push({name: item.name})
    },
    isCollapse() {
      return this.$store.state.isCollapse
    }
  },
  // computed: {
  //   noChildren() {
  //     return this.menu.filter((item) => !item.children)
  //   },
  //   hasChildren() {
  //     return this.menu.filter((item) => item.children)
  //   }
  // }
}

</script>

<style scoped>
.el-menu {
  height: 100vh;
}
</style>